home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / ISSUE08 / DATADICT / CPFILE.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1995-04-24  |  2.3 KB  |  90 lines

  1. unit Cpfile;
  2.  
  3. interface
  4.  
  5. uses
  6.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  7.   Forms, Dialogs, StdCtrls;
  8.  
  9. type
  10.   TForm1 = class(TForm)
  11.     Edit1: TEdit;
  12.     Button1: TButton;
  13.     Button2: TButton;
  14.     procedure FormCreate(Sender: TObject);
  15.     procedure Button1Click(Sender: TObject);
  16.     procedure Button2Click(Sender: TObject);
  17.   private
  18.     { Private declarations }
  19.   public
  20.     { Public declarations }
  21.   end;
  22.  
  23. var
  24.   Form1: TForm1;
  25.   i: comp;
  26.  
  27. implementation
  28.  
  29. {$R *.DFM}
  30.  
  31. uses LZExpand;
  32.  
  33. procedure CopyFile(Source, Dest: String);
  34. var
  35.   SourceHand, DestHand: Integer;
  36.   OpenBuf: TOFStruct;
  37. begin
  38.   { Place null-terminators at the end of the strings, so we can emulate a }
  39.   { PChar.  Note that (for safety) this will truncate a string if it is   }
  40.   { 255 characters long, but that's beyond the DOS filename limit anyway. }
  41.   if Source[0] = #255 then
  42.     Source[0] := #254
  43.   Source[Ord(Source[0]) + 1] := #0;
  44.   Dest[Ord(Dest[0]) + 1] := #0;
  45.   { Open source file, and pass our psuedo-PChar as the filename }
  46.   SourceHand := LZOpenFile(@Source[1], OpenBuf, of_Share_Deny_Write or of_Read);
  47.   { raise an exception on error }
  48.   if SourceHand = -1 then
  49.     raise EInOutError.Create('Error opening source file');
  50.   { Open destination file, and pass our psuedo-PChar as the filename }
  51.   DestHand := LZOpenFile(@Dest[1], OpenBuf, of_Share_Exclusive or of_Write
  52.                          or of_Create);
  53.   { close source and raise exception on error }
  54.   if DestHand = -1 then begin
  55.     LZClose(SourceHand);
  56.     raise EInOutError.Create('Error opening destination file');
  57.   end;
  58.   try
  59.     { copy source to dest, raise exception on error }
  60.     if LZCopy(SourceHand, DestHand) < 0 then
  61.       raise EInOutError.Create('Error copying file');
  62.   finally
  63.     { whether or not an exception occurs, we need to close the files }
  64.     LZClose(SourceHand);
  65.     LZClose(DestHand);
  66.   end;
  67. end;
  68.  
  69.  
  70.  
  71. procedure TForm1.FormCreate(Sender: TObject);
  72. begin
  73.   Edit1.Text := IntToStr(SizeOf(i));
  74. end;
  75.  
  76. procedure TForm1.Button1Click(Sender: TObject);
  77. begin
  78.   CopyFile('c:\temp.exe', 'c:\xxx.exe');
  79. end;
  80.  
  81. procedure TForm1.Button2Click(Sender: TObject);
  82. var
  83.   l: double;
  84. begin
  85.   l := 3.5995044332;
  86.   Edit1.Text := IntToStr(Round(l));
  87. end;
  88.  
  89. end.
  90.